package com.songshuai.webapi.baseapi.service.impl;

import com.songshuai.webapi.baseapi.dao.YixueBaseCampusSchoolMapper;
import com.songshuai.webapi.baseapi.dto.request.CampusBindSchoolReqDto;
import com.songshuai.webapi.baseapi.dto.request.CampusDeleteSchoolReqDto;
import com.songshuai.webapi.baseapi.model.YixueBaseCampusSchool;
import com.songshuai.webapi.baseapi.service.CampusSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class CampusSchoolServiceImpl implements CampusSchoolService {


    @Autowired
    private YixueBaseCampusSchoolMapper campusSchoolMapper;


    @Override
    @Transactional
    public void addSchool(CampusBindSchoolReqDto reqDto) {
        Date date = new Date();
        campusSchoolMapper.deleteByCampusId(reqDto.getCampusId());
        for (Integer schoolId:reqDto.getSchoolId()) {
            YixueBaseCampusSchool entity = new YixueBaseCampusSchool();
            entity.setCampusId(reqDto.getCampusId());
            entity.setSchoolId(schoolId);
            entity.setCreateTime(date);
            entity.setUpdateTime(date);
            campusSchoolMapper.insertSelective(entity);
        }

    }

    @Override
    public void deleteSchool(CampusDeleteSchoolReqDto reqDto) {
        campusSchoolMapper.deleteByCampusIdAndschoolId(reqDto);
    }
}
